package shellSort;

import insertSort.MyInsertSort;

import java.util.Arrays;
import java.util.Random;

/**
 * 测试希尔排序
 * 空间复杂度:O(1)
 * 时间复杂度：O(N^ 1.3~1.6)
 * 稳定性：不稳定
 */
public class TestShellSort {

    //测试希尔排序所用时间
    public static void testShellSort(int[] array) {
        long startTime = System.currentTimeMillis();
        MyShellSort.shellSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序耗时:"+(endTime - startTime)+"ms");
    }



    public static void main(String[] args) {

        int[] array = new int[10_0000];
        //initArrayOrder(array);//无序
        initArrayNotOrder(array); //有序

        testShellSort(array);
        //System.out.println(Arrays.toString(array));
    }

    public static void initArrayOrder(int[] array) {
        //有序的初始化
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
    }
    public static void initArrayNotOrder(int[] array) {
        //不有序的初始化
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }
}
